package exception

func NewApiException(code int, message string) *ApiException {
	return &ApiException{
		Code:    code,
		Message: message,
	}
}

type ApiException struct {
	Code    int    `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
	// 标准Http Code ,不在body返回，走标准http response
	// 该值在response包中定义 httpCode := http.StatusInternalServerError
	HttpCode int `json:"-"`
}

// 实现 error interface{Error() string}
//

func (a *ApiException) Error() string {
	return a.Message
}

func (a *ApiException) WithHttpCode(code int) *ApiException {
	a.HttpCode = code
	return a
}

func (a *ApiException) WithMessage(msg string) *ApiException {
	a.Message = msg
	return a
}
